package client.comm.baoding.adapter.page

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import client.comm.baoding.fragment.Zz2OneFragment
import client.comm.baoding.fragment.Zz2TwoFragment
import client.comm.baoding.utils.Constants
import client.comm.commlib.utils.SharedUtil

class Zz2FragmentPageAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {

    val fragments: Array<Fragment?> by lazy {
        arrayOfNulls(2)
    }

    override fun getItem(position: Int): Fragment {
        if (position == 0 && fragments[0] == null) {
            fragments[0] = Zz2OneFragment()
        } else if (position == 1 && fragments[1] == null) {
            fragments[1] = Zz2TwoFragment()
        }
        return fragments[position]!!
        /*.apply {
                arguments = Bundle().apply {
                    putInt("fragmentID", position)
                }
            }*/
    }

    override fun getCount(): Int {
        return fragments.size
    }

    override fun getPageTitle(position: Int): CharSequence? {
        var titleId: String = ""

        if (position == 0 && fragments[0] == null) {
            titleId = "转账给他人"
        } else if (position == 1 && fragments[1] == null) {

            val tag: String = if (SharedUtil.read(Constants.IS_ZEROHOST, "").isNullOrEmpty()) {
                "子系统"
            } else {
                "主系统"
            }
            titleId = "转账至$tag"
        }
        return titleId
    }
}